/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.servinf.ani.mapper;

import static com.servinf.ani.mapper.AssignmentMapper.Aportaalameta_T;
import com.servinf.ani.sincronizador.App;
import com.servinf.ani.sincronizador.entities.Ambiental;
import com.servinf.ani.sincronizador.entities.Intervencion;
import com.servinf.ani.sincronizador.entities.Planeacion;
import com.servinf.ani.sincronizador.entities.Predial;
import com.servinf.ani.sincronizador.entities.Social;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.poi.ss.usermodel.DateUtil;

/**
 *
 * @author David
 */
public class AreaMapper {
    
    
      public static Predial getPredial(List<Object> excelRow, Predial predial, Integer assignmentId) {
          if(predial == null) {
              predial = new Predial();
              predial.setIdIntervencion(new Intervencion(assignmentId));
          }
          
          if(excelRow.get(AssignmentMapper.PrediosRequeridos_T) != null) {
                AssignmentMapper.currentField = "PrediosRequeridos_T";
                Integer value = ((Double) excelRow.get(AssignmentMapper.PrediosRequeridos_T)).intValue();
                predial.setPrediosRequeridos(value);
          }
          
          if(excelRow.get(AssignmentMapper.Prediosdisponibles_T) != null) {
                AssignmentMapper.currentField = "Prediosdisponibles_T";
                Integer value = ((Double) excelRow.get(AssignmentMapper.Prediosdisponibles_T)).intValue();
                predial.setPrediosDisponibles(value);
          }
          
          if(excelRow.get(AssignmentMapper.LongPrediosDisp_T) != null) {
                AssignmentMapper.currentField = "LongPrediosDisp_T";
                Integer value = ((Double) excelRow.get(AssignmentMapper.LongPrediosDisp_T)).intValue();
                predial.setLongitudPrediosDisp(value);
          }
          
          if(excelRow.get(AssignmentMapper.Prediosconproblemas_T) != null) {
                AssignmentMapper.currentField = "Prediosconproblemas_T";
                Integer value = ((Double) excelRow.get(AssignmentMapper.Prediosconproblemas_T)).intValue();
                predial.setPrediosProblema(value);
          }
          
          if(excelRow.get(AssignmentMapper.LongPrediosProblemas_T) != null) {
                AssignmentMapper.currentField = "LongPrediosProblemas_T";
                Integer value = ((Double) excelRow.get(AssignmentMapper.LongPrediosProblemas_T)).intValue();
                predial.setLongPrediosProblem(value);
          }
          
          if(excelRow.get(AssignmentMapper.PrediosEnajenaciónVoluntaria_T) != null) {
                AssignmentMapper.currentField = "PrediosEnajenaciónVoluntaria_T";
                Integer value = ((Double) excelRow.get(AssignmentMapper.PrediosEnajenaciónVoluntaria_T)).intValue();
                predial.setPrediosEnajenacionVol(value);
          }
          
          if(excelRow.get(AssignmentMapper.PrediosExpropiación_T) != null) {
                AssignmentMapper.currentField = "PrediosExpropiación_T";
                Integer value = ((Double) excelRow.get(AssignmentMapper.PrediosExpropiación_T)).intValue();
                predial.setPrediosExpropiacion(value);
          }
          
          return predial;
          
          
      }
      
      
      public static Ambiental getAmbiental(List<Object> excelRow, Ambiental ambiental, Integer assignmentId) throws ParseException {
          if(ambiental == null) {
              ambiental = new Ambiental();
              ambiental.setIdIntervencion(new Intervencion(assignmentId));
          }
          
          if(excelRow.get(AssignmentMapper.EstadoTrámite_T) != null) {
                AssignmentMapper.currentField = "EstadoTrámite_T";
                ambiental.setEstadoTramite((String) excelRow.get(AssignmentMapper.EstadoTrámite_T));
          }
          
          if(excelRow.get(AssignmentMapper.Actores_T) != null) {
                AssignmentMapper.currentField = "Actores_T";
                ambiental.setActores((String) excelRow.get(AssignmentMapper.Actores_T));
          }
          
          if(excelRow.get(AssignmentMapper.FechadePronunciamiento_T) != null) {
                AssignmentMapper.currentField = "FechadePronunciamiento_T";
                Double dateNumeric = (Double) excelRow.get(AssignmentMapper.FechadePronunciamiento_T);
                Date date = DateUtil.getJavaDate(dateNumeric);
                ambiental.setFechaPronunciamiento(date);
          }
                    
          if(excelRow.get(AssignmentMapper.FechadeRadicación_T) != null) {
                AssignmentMapper.currentField = "FechadeRadicación_T";
                Double dateNumeric = (Double) excelRow.get(AssignmentMapper.FechadeRadicación_T);
                Date date = DateUtil.getJavaDate(dateNumeric);
                ambiental.setFechaRadicacion(date);
          }
          
          return ambiental;
      }
      
      public static Social getSocial(List<Object> excelRow, Social social, Integer assignmentId) throws ParseException {
          if(social == null) {
              social = new Social();
              social.setIdIntervencion(new Intervencion(assignmentId));
          }
          
          if(excelRow.get(AssignmentMapper.EstadoTrámite_T) != null) {
                AssignmentMapper.currentField = "EstadoTrámite_T";
                social.setEstadoTramite((String) excelRow.get(AssignmentMapper.EstadoTrámite_T));
          }
          
          if(excelRow.get(AssignmentMapper.Actores_T) != null) {
                AssignmentMapper.currentField = "Actores_T";
                social.setActores((String) excelRow.get(AssignmentMapper.Actores_T));
          }
          
          
          if(excelRow.get(AssignmentMapper.FechadePronunciamiento_T) != null) {
                AssignmentMapper.currentField = "FechadePronunciamiento_T";
                Double dateNumeric = (Double) excelRow.get(AssignmentMapper.FechadePronunciamiento_T);
                Date date = DateUtil.getJavaDate(dateNumeric);
                social.setFechaPronunciamiento(date);
          }
                    
          if(excelRow.get(AssignmentMapper.FechadeRadicación_T) != null) {
                AssignmentMapper.currentField = "FechadeRadicación_T";
                Double dateNumeric = (Double) excelRow.get(AssignmentMapper.FechadeRadicación_T);
                Date date = DateUtil.getJavaDate(dateNumeric);
                social.setFechaRadicacion(date);
          }
          
          return social;
      }
      
      public static Planeacion getPlaneacion(List<Object> excelRow, Planeacion planeacion, Integer assignmentId) throws ParseException{
          if(planeacion == null) {
              planeacion = new Planeacion();
              planeacion.setIdIntervencion(new Intervencion(assignmentId));
          }
          
          if(excelRow.get(AssignmentMapper.Aportaalameta_T) != null) {
                AssignmentMapper.currentField = "Aportaalameta_T";
                Boolean aportaAMeta = Boolean.parseBoolean((String) excelRow.get(AssignmentMapper.Aportaalameta_T));
                planeacion.setAporteMeta(aportaAMeta);
          }
          
          if(excelRow.get(AssignmentMapper.LongitudContractual_T) != null) {
                //Se están recibiendo valores del tipo 15,72000 en String
                AssignmentMapper.currentField = "LongitudContractual_T";
                String numberString = ((String) excelRow.get(AssignmentMapper.LongitudContractual_T)).replace(",", ".");
                Double value = Double.parseDouble(numberString);
                planeacion.setLongContractual(value);
          }
          
          if(excelRow.get(AssignmentMapper.Trabajo) != null) {
                AssignmentMapper.currentField = "Trabajo";
                planeacion.setMetaAnual(((Double) excelRow.get(AssignmentMapper.Trabajo)).intValue());
          }
          
          if(excelRow.get(AssignmentMapper.Trabajoreal) != null) {
                AssignmentMapper.currentField = "Trabajoreal";
                planeacion.setEjecucionAnual(((Double) excelRow.get(AssignmentMapper.Trabajoreal)).intValue());
          }
          
          
          return planeacion;
      }
    
    
}
